require "event_editor/gadgets/switch_button"
require 'gadgets/combobox'

module EventEditor
  module Conditions
    class Switch < Gtk::VBox
      def initialize(base, model)
        super()
        @model = model

        box = Gtk::HBox.new
        @@switch_input = EventEditor::Gadgets::SwitchButton.new(base, @model.switches) do |arr|
          @model.switches = arr
        end
        box.pack_start(@@switch_input, false, false)
        box.pack_start(Gtk::Label.new("is"))
        @@combobox = ::Gadgets::Combobox.new([['ON', 'on'], ['OFF', 'off']], [String, String])
        box.pack_start(@@combobox, false, false)
        self.add(box)
      end
      
      def commands
        return ['switch', @@switch_input.value, @@combobox.selected_data]
      end
      
      def self.load(command)
        @@switch_input.value = command[1]
        @@combobox.select(command[2])
      end
      
      def self.command_to_s(model, args)
        arr = {'on' => 'ON', 'off' => 'OFF'}
        return "[" + args[1].to_s + ": " + model.switches[args[1]] + "] is " + arr[args[2]]
      end
    end
  end
end